<template>
    <h2>修改科室</h2>
    <table border="1">
        <tr>
            <td>科室名称</td>
            <td>
                <input type="text" v-model="info.KeiShiName">
            </td>
        </tr>
        <tr>
            <td>科室介绍</td>
            <td>
               <textarea v-model="info.KeiShiInfo"></textarea>
            </td>
        </tr>
       
        <tr>
            <td>科室人数</td>
            <td>
                <input type="number" v-model="info.KeiShiNum">
            </td>
        </tr>
        
        <tr>
            <td></td>
            <td>
                <input type="button" value="修改" @click="SaveData">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import axios from "axios";
import { onMounted ,ref} from "vue";

import{useCounterStore}from '../../stores/counter.ts';


const Counters=useCounterStore();

import { useRoute ,useRouter} from "vue-router";

const router=useRouter();

const route=useRoute();

//反填
const LoData=()=>{
    axios.get('https://localhost:7133/api/KeiShi/GetKeiShi',
    {
       params:{
        KeiShiId:route.params.id
       }
    }
    )
    .then(res=>{
        info.value=res.data
    })
}

onMounted(()=>{
    GetUtype();
    LoData();

})



const info=ref({
    KeiShiName:"",
    KeiShiInfo:"",
   
    KeiShiNum:"",
   
})



const UserType=ref("");
const SaveData=()=>{

    

axios.put('https://localhost:7133/api/KeiShi/UpdateKeiShi',{

    KeiShiName:info.value.KeiShiName,
    KeiShiInfo:info.value.KeiShiInfo,  
    KeiShiNum:info.value.KeiShiNum,
    D_AddUser:Counters.MemberName
  
})
.then(res=>{
    
     if(res.data>0){
        alert("修改成功");
        router.push("/ShowKeiShi");
    }
    else{
        alert("修改失败");
    }
})

}

const GetUtype=()=>{
    axios.get('https://localhost:7133/api/KeiShi/GetMemberType',
    {
        params:{
            MemberName:Counters.MemberName
        }
    }
    )
    .then(res=>{
        UserType.value=res.data[0];
    })
}
</script>
